package com.example.searchservice.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@Controller
@RequestMapping("/")
public class SseController {

    // 方法1: 直接返回视图名
    @GetMapping("/index")
    public String index() {
        return "index"; // 对应 templates/index.html
    }

    @GetMapping("/receiver")
    public String receiver() {
        return "receiver"; // 对应 templates/index.html
    }


    // 方法2: 使用Model传递数据
    @GetMapping("/home")
    public String home(Model model) {
        model.addAttribute("message", "Hello Thymeleaf!");
        model.addAttribute("currentTime", new Date());
        return "index";
    }

    @GetMapping("/receiver2")
    public String receiver2(Model model) {
        model.addAttribute("message", "Hello Thymeleaf!");
        model.addAttribute("currentTime", new Date());
        return "receiver";
    }

    // 方法3: 重定向到首页
    @GetMapping("/redirect-to-index")
    public String redirectToIndex() {
        return "redirect:/";
    }
}
